{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "日期：11/17  \n",
    "撰写人：林尚仪   \n",
    "\n",
    "-----\n",
    "\n",
    "## 课堂学习内容：\n",
    "\n",
    "> * 1、高德API-WEB服务    \n",
    "> * 2、API经济成本的预估（调用量、并发量）   \n",
    "> * 3、地理编码\n",
    "...\n",
    "\n",
    "## 课后练习：\n",
    "\n",
    "> * 1、[地理编码](https://lbs.amap.com/api/webservice/guide/api/georegeo)   \n",
    "> * 2、[路径规划](http://lbs.amap.com/api/webservice/guide/api/direction)   \n",
    "..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json\n",
    "import pandas as pd\n",
    "lin_key = \"1b65ec2cb8c9419c9b3d6b49b3c001d7\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 地理编码\n",
    "\n",
    "> * 1、结构化地址的定义： 首先，地址肯定是一串字符，内含国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦等建筑物名称。按照由大区域名称到小区域名称组合在一起的字符。一个有效的地址应该是独一无二的。注意：针对大陆、港、澳地区的地理编码转换时可以将国家信息选择性的忽略，但省、市、城镇等级别的地址构成是不能忽略的。暂时不支持返回台湾省的详细地址信息。    \n",
    "> * 2、url:https://restapi.amap.com/v3/geocode/geo?parameters      \n",
    "> * 3、requests.get()       \n",
    "> * 4、参数：   \n",
    "\n",
    ">> * A.必选：key（高德API秘钥），address(结构化地址)  \n",
    ">> * B.可选："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### 准备数据 请思考：高德API是怎么获取数据的？数据库查询\n",
    "中大南方_address = \"广东省广州市中山大学南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "params = {\n",
    "    \"key\":lin_key,\n",
    "    \"address\": 中大南方_address\n",
    "}\n",
    "# positional argument follows keyword argument\n",
    "# pa 一定要放在前面，keyword argument放在末尾！！！可以\n",
    "response = requests.get(url,params=params)\n",
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "中大南方_location = response.json()['geocodes'][0]['location']\n",
    "中大南方_location"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 逆地理编码\n",
    "\n",
    "> * A.url : https://restapi.amap.com/v3/geocode/regeo?parameters    \n",
    "> * B.requests.get()    \n",
    "> * C.参数：    \n",
    "\n",
    ">> * 1、必选：key,location(经纬度坐标)\n",
    ">> * 2、可选: extensions[(默认：base)可选\"all\",描述数据详细指数]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据准备 中大南方_location"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url = \"https://restapi.amap.com/v3/geocode/regeo?parameters\"\n",
    "params = {\n",
    "    \"key\":lin_key,\n",
    "    \"location\":中大南方_location,\n",
    "    \"extensions\":\"all\"\n",
    "}\n",
    "r = requests.get(url,params)\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['博学路', '中山路', 'S29从莞深高速']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_roads_ = []\n",
    "for item in r.json()['regeocode']['roads']:\n",
    "#     print(item['name'])\n",
    "    _roads_.append(item['name'])\n",
    "_roads_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'regeocode': {'roads': [{'id': '020F49F0050461203',\n",
       "    'location': '113.68,23.634',\n",
       "    'direction': '南',\n",
       "    'name': '博学路',\n",
       "    'distance': '156.951'},\n",
       "   {'id': '020F49F0050462451',\n",
       "    'location': '113.677,23.6347',\n",
       "    'direction': '东南',\n",
       "    'name': '中山路',\n",
       "    'distance': '343.951'},\n",
       "   {'id': '020F49F006047765',\n",
       "    'location': '113.682,23.6394',\n",
       "    'direction': '南',\n",
       "    'name': 'S29从莞深高速',\n",
       "    'distance': '807.947'}],\n",
       "  'roadinters': [{'second_name': '中山路',\n",
       "    'first_id': '020F49F0050461203',\n",
       "    'second_id': '020F49F0050462451',\n",
       "    'location': '113.676794,23.634661',\n",
       "    'distance': '343.951',\n",
       "    'first_name': '博学路',\n",
       "    'direction': '东南'}],\n",
       "  'formatted_address': '广东省广州市从化区温泉镇中山大学南方学院',\n",
       "  'addressComponent': {'city': '广州市',\n",
       "   'province': '广东省',\n",
       "   'adcode': '440117',\n",
       "   'district': '从化区',\n",
       "   'towncode': '440117103000',\n",
       "   'streetNumber': {'number': '7号',\n",
       "    'location': '113.678600,23.633329',\n",
       "    'direction': '西北',\n",
       "    'distance': '109.203',\n",
       "    'street': '博学路'},\n",
       "   'country': '中国',\n",
       "   'township': '温泉镇',\n",
       "   'businessAreas': [[]],\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'citycode': '020'},\n",
       "  'aois': [{'area': '536585.849985',\n",
       "    'type': '141201',\n",
       "    'id': 'B00140MR9A',\n",
       "    'location': '113.679262,23.632583',\n",
       "    'adcode': '440117',\n",
       "    'name': '中山大学南方学院',\n",
       "    'distance': '0'}],\n",
       "  'pois': [{'id': 'B00140MR9A',\n",
       "    'direction': '西',\n",
       "    'businessarea': [],\n",
       "    'address': '温泉大道882号',\n",
       "    'poiweight': '0.450402',\n",
       "    'name': '中山大学南方学院',\n",
       "    'location': '113.679262,23.632583',\n",
       "    'distance': '2.69979',\n",
       "    'tel': '020-61787331',\n",
       "    'type': '科教文化服务;学校;高等院校'},\n",
       "   {'id': 'B0FFF2VMJ4',\n",
       "    'direction': '东南',\n",
       "    'businessarea': [],\n",
       "    'address': '温泉大道886号中山大学南方学院内',\n",
       "    'poiweight': '0.148531',\n",
       "    'name': '中山大学南方学院-综合楼',\n",
       "    'location': '113.680117,23.631544',\n",
       "    'distance': '142.466',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;学校;学校'},\n",
       "   {'id': 'B0FFFTC9PH',\n",
       "    'direction': '东北',\n",
       "    'businessarea': [],\n",
       "    'address': '从莞深高速(中山大学南方学院)',\n",
       "    'poiweight': '0.193172',\n",
       "    'name': '中山大学南方学院教学楼10号',\n",
       "    'location': '113.680125,23.633492',\n",
       "    'distance': '132.988',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B00141TQKX',\n",
       "    'direction': '西北',\n",
       "    'businessarea': [],\n",
       "    'address': '温泉大道882',\n",
       "    'poiweight': '0.148531',\n",
       "    'name': '中山大学南方学院教学楼6号',\n",
       "    'location': '113.678424,23.633710',\n",
       "    'distance': '153.818',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;学校;学校'},\n",
       "   {'id': 'B00141TQGR',\n",
       "    'direction': '西北',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路7',\n",
       "    'poiweight': '0.148531',\n",
       "    'name': '中山大学南方学院教学楼7号',\n",
       "    'location': '113.678600,23.633330',\n",
       "    'distance': '109.298',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;学校;高等院校'},\n",
       "   {'id': 'B00141WQCO',\n",
       "    'direction': '东北',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路',\n",
       "    'poiweight': '0.14954',\n",
       "    'name': '中山大学南方学院教学楼8号',\n",
       "    'location': '113.680399,23.634329',\n",
       "    'distance': '225.543',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFG9IORM',\n",
       "    'direction': '西北',\n",
       "    'businessarea': [],\n",
       "    'address': '温泉大道882号中山大学南方学院内',\n",
       "    'poiweight': '0.287887',\n",
       "    'name': '中山大学南方学院-图书馆',\n",
       "    'location': '113.679177,23.632762',\n",
       "    'distance': '23.6163',\n",
       "    'tel': '020-61787368;020-61787371',\n",
       "    'type': '科教文化服务;图书馆;图书馆'},\n",
       "   {'id': 'B0FFKP9EQJ',\n",
       "    'direction': '东',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路附近',\n",
       "    'poiweight': '0.191742',\n",
       "    'name': '中山大学南方学院4号实验楼',\n",
       "    'location': '113.679963,23.632652',\n",
       "    'distance': '69.4077',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFJKIA10',\n",
       "    'direction': '东北',\n",
       "    'businessarea': [],\n",
       "    'address': '温泉大道882号中山大学南方学院',\n",
       "    'poiweight': '0.191691',\n",
       "    'name': '中山大学南方学院-第11教学楼',\n",
       "    'location': '113.680037,23.633173',\n",
       "    'distance': '101.294',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B00141TRVH',\n",
       "    'direction': '西南',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路21',\n",
       "    'poiweight': '0.148531',\n",
       "    'name': '中山大学南方学院教学楼2号',\n",
       "    'location': '113.677060,23.631346',\n",
       "    'distance': '264.846',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFKERBQZ',\n",
       "    'direction': '西北',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路7号附近',\n",
       "    'poiweight': '0.289141',\n",
       "    'name': '中山大学南方学院惟贤门',\n",
       "    'location': '113.678437,23.633721',\n",
       "    'distance': '154.082',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;学校;高等院校'},\n",
       "   {'id': 'B0FFKP81F4',\n",
       "    'direction': '东北',\n",
       "    'businessarea': [],\n",
       "    'address': '中山路',\n",
       "    'poiweight': '0.191742',\n",
       "    'name': '政商研究院教学楼9号',\n",
       "    'location': '113.679949,23.633919',\n",
       "    'distance': '163.951',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFKP9ET5',\n",
       "    'direction': '西南',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路附近',\n",
       "    'poiweight': '0.191742',\n",
       "    'name': '中山大学南方学院1号实验楼',\n",
       "    'location': '113.678215,23.631370',\n",
       "    'distance': '172.86',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B00141TR76',\n",
       "    'direction': '西南',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路29',\n",
       "    'poiweight': '0.052819',\n",
       "    'name': '中山大学南方学院教学楼4号',\n",
       "    'location': '113.677460,23.630490',\n",
       "    'distance': '297.315',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFKP7Q5N',\n",
       "    'direction': '西南',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路',\n",
       "    'poiweight': '0.191742',\n",
       "    'name': '中山大学南方学院2号实验楼',\n",
       "    'location': '113.678211,23.630956',\n",
       "    'distance': '210.76',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B00140TWHT',\n",
       "    'direction': '南',\n",
       "    'businessarea': [],\n",
       "    'address': '笃行路2号',\n",
       "    'poiweight': '0.157653',\n",
       "    'name': '教工住宅1号',\n",
       "    'location': '113.678490,23.630432',\n",
       "    'distance': '251.758',\n",
       "    'tel': [],\n",
       "    'type': '商务住宅;住宅区;住宅小区'},\n",
       "   {'id': 'B0G3ARGF5Y',\n",
       "    'direction': '西',\n",
       "    'businessarea': [],\n",
       "    'address': [],\n",
       "    'poiweight': '0.286321',\n",
       "    'name': '中山大学南方学院教学楼1号',\n",
       "    'location': '113.677077,23.631783',\n",
       "    'distance': '241.753',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;学校;高等院校'},\n",
       "   {'id': 'B0FFLBEOND',\n",
       "    'direction': '东南',\n",
       "    'businessarea': [],\n",
       "    'address': '从莞深高速(中山大学南方学院)',\n",
       "    'poiweight': '0.190963',\n",
       "    'name': '聚贤楼10号',\n",
       "    'location': '113.681253,23.631036',\n",
       "    'distance': '263.444',\n",
       "    'tel': [],\n",
       "    'type': '商务住宅;住宅区;宿舍'},\n",
       "   {'id': 'B0FFKP81F0',\n",
       "    'direction': '西',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路19号附近',\n",
       "    'poiweight': '0.191742',\n",
       "    'name': '教学楼1号(文学与传媒学院)',\n",
       "    'location': '113.676866,23.631736',\n",
       "    'distance': '263.674',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFKP838K',\n",
       "    'direction': '西南',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路25',\n",
       "    'poiweight': '0.191742',\n",
       "    'name': '教学楼3号(外国语学院)',\n",
       "    'location': '113.677247,23.630947',\n",
       "    'distance': '275.62',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFJLW0O9',\n",
       "    'direction': '西',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路4附近',\n",
       "    'poiweight': '0.191645',\n",
       "    'name': '中山大学南方学院西区饭堂',\n",
       "    'location': '113.676210,23.632177',\n",
       "    'distance': '316.572',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFKPXMCN',\n",
       "    'direction': '北',\n",
       "    'businessarea': [],\n",
       "    'address': '中山路',\n",
       "    'poiweight': '0.191739',\n",
       "    'name': '中山大学南方学院音乐系',\n",
       "    'location': '113.678792,23.635389',\n",
       "    'distance': '316.942',\n",
       "    'tel': [],\n",
       "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
       "   {'id': 'B0FFJBZLYT',\n",
       "    'direction': '西北',\n",
       "    'businessarea': [],\n",
       "    'address': '中山路与博学路交叉口东南50米',\n",
       "    'poiweight': '0.297382',\n",
       "    'name': '铜像广场',\n",
       "    'location': '113.676921,23.634555',\n",
       "    'distance': '326.444',\n",
       "    'tel': [],\n",
       "    'type': '风景名胜;风景名胜;风景名胜'},\n",
       "   {'id': 'B0FFG8CSEK',\n",
       "    'direction': '东',\n",
       "    'businessarea': [],\n",
       "    'address': '从莞深高速(中山大学南方学院)',\n",
       "    'poiweight': '0.185371',\n",
       "    'name': 'L5员工宿舍',\n",
       "    'location': '113.682583,23.631487',\n",
       "    'distance': '356.923',\n",
       "    'tel': [],\n",
       "    'type': '商务住宅;住宅区;宿舍'},\n",
       "   {'id': 'B0FFKPXO2S',\n",
       "    'direction': '北',\n",
       "    'businessarea': [],\n",
       "    'address': '博学路附近',\n",
       "    'poiweight': '0.188247',\n",
       "    'name': '中山大学南方学院医务室',\n",
       "    'location': '113.679394,23.635924',\n",
       "    'distance': '372.556',\n",
       "    'tel': [],\n",
       "    'type': '医疗保健服务;医疗保健服务场所;医疗保健服务场所'},\n",
       "   {'id': 'B0FFH6K3U9',\n",
       "    'direction': '西南',\n",
       "    'businessarea': [],\n",
       "    'address': '温泉镇温泉大道882号中大南方H7栋1-5层',\n",
       "    'poiweight': '0.254885',\n",
       "    'name': '广州中大南方招待所',\n",
       "    'location': '113.676330,23.631332',\n",
       "    'distance': '331.438',\n",
       "    'tel': '020-61787222',\n",
       "    'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
       "   {'id': 'B0FFHHLMF8',\n",
       "    'direction': '东北',\n",
       "    'businessarea': [],\n",
       "    'address': '中山大学南方学院明辩路2号第三饭堂',\n",
       "    'poiweight': '0.178935',\n",
       "    'name': '茗语轩餐厅',\n",
       "    'location': '113.681901,23.634495',\n",
       "    'distance': '341.332',\n",
       "    'tel': '13929501395;13533390928',\n",
       "    'type': '餐饮服务;中餐厅;中餐厅'},\n",
       "   {'id': 'B0FFLJV996',\n",
       "    'direction': '东南',\n",
       "    'businessarea': [],\n",
       "    'address': [],\n",
       "    'poiweight': '0.286264',\n",
       "    'name': '保利桃花源66BLOCK',\n",
       "    'location': '113.682954,23.631008',\n",
       "    'distance': '412.208',\n",
       "    'tel': [],\n",
       "    'type': '商务住宅;住宅区;住宅小区'},\n",
       "   {'id': 'B0FFKPXY26',\n",
       "    'direction': '北',\n",
       "    'businessarea': [],\n",
       "    'address': '从莞深高速公路',\n",
       "    'poiweight': '0.21826',\n",
       "    'name': '中山大学南方学院聚贤楼5号',\n",
       "    'location': '113.680265,23.636313',\n",
       "    'distance': '427.447',\n",
       "    'tel': [],\n",
       "    'type': '商务住宅;商务住宅相关;商务住宅相关'},\n",
       "   {'id': 'B0FFGXGN3K',\n",
       "    'direction': '东',\n",
       "    'businessarea': [],\n",
       "    'address': '中山大学南方学院',\n",
       "    'poiweight': '0.188657',\n",
       "    'name': '中山大学南方学院宿舍H25',\n",
       "    'location': '113.683474,23.632020',\n",
       "    'distance': '430.984',\n",
       "    'tel': [],\n",
       "    'type': '商务住宅;住宅区;宿舍'}]},\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 请计算该列表中出现聚贤楼的个数？并把它们放在一个新列表中？\n",
    "# 期中测试的数据很大 1379*76"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>direction</th>\n",
       "      <th>businessarea</th>\n",
       "      <th>address</th>\n",
       "      <th>poiweight</th>\n",
       "      <th>name</th>\n",
       "      <th>location</th>\n",
       "      <th>distance</th>\n",
       "      <th>tel</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>B00140MR9A</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道882号</td>\n",
       "      <td>0.450402</td>\n",
       "      <td>中山大学南方学院</td>\n",
       "      <td>113.679262,23.632583</td>\n",
       "      <td>2.69979</td>\n",
       "      <td>020-61787331</td>\n",
       "      <td>科教文化服务;学校;高等院校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B0FFF2VMJ4</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道886号中山大学南方学院内</td>\n",
       "      <td>0.148531</td>\n",
       "      <td>中山大学南方学院-综合楼</td>\n",
       "      <td>113.680117,23.631544</td>\n",
       "      <td>142.466</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;学校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B0FFFTC9PH</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>从莞深高速(中山大学南方学院)</td>\n",
       "      <td>0.193172</td>\n",
       "      <td>中山大学南方学院教学楼10号</td>\n",
       "      <td>113.680125,23.633492</td>\n",
       "      <td>132.988</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>B00141TQKX</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道882</td>\n",
       "      <td>0.148531</td>\n",
       "      <td>中山大学南方学院教学楼6号</td>\n",
       "      <td>113.678424,23.633710</td>\n",
       "      <td>153.818</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;学校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>B00141TQGR</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路7</td>\n",
       "      <td>0.148531</td>\n",
       "      <td>中山大学南方学院教学楼7号</td>\n",
       "      <td>113.678600,23.633330</td>\n",
       "      <td>109.298</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;高等院校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>B00141WQCO</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路</td>\n",
       "      <td>0.14954</td>\n",
       "      <td>中山大学南方学院教学楼8号</td>\n",
       "      <td>113.680399,23.634329</td>\n",
       "      <td>225.543</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>B0FFG9IORM</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道882号中山大学南方学院内</td>\n",
       "      <td>0.287887</td>\n",
       "      <td>中山大学南方学院-图书馆</td>\n",
       "      <td>113.679177,23.632762</td>\n",
       "      <td>23.6163</td>\n",
       "      <td>020-61787368;020-61787371</td>\n",
       "      <td>科教文化服务;图书馆;图书馆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>B0FFKP9EQJ</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路附近</td>\n",
       "      <td>0.191742</td>\n",
       "      <td>中山大学南方学院4号实验楼</td>\n",
       "      <td>113.679963,23.632652</td>\n",
       "      <td>69.4077</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>B0FFJKIA10</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉大道882号中山大学南方学院</td>\n",
       "      <td>0.191691</td>\n",
       "      <td>中山大学南方学院-第11教学楼</td>\n",
       "      <td>113.680037,23.633173</td>\n",
       "      <td>101.294</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>B00141TRVH</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路21</td>\n",
       "      <td>0.148531</td>\n",
       "      <td>中山大学南方学院教学楼2号</td>\n",
       "      <td>113.677060,23.631346</td>\n",
       "      <td>264.846</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>B0FFKERBQZ</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路7号附近</td>\n",
       "      <td>0.289141</td>\n",
       "      <td>中山大学南方学院惟贤门</td>\n",
       "      <td>113.678437,23.633721</td>\n",
       "      <td>154.082</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;高等院校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>B0FFKP81F4</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>中山路</td>\n",
       "      <td>0.191742</td>\n",
       "      <td>政商研究院教学楼9号</td>\n",
       "      <td>113.679949,23.633919</td>\n",
       "      <td>163.951</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>B0FFKP9ET5</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路附近</td>\n",
       "      <td>0.191742</td>\n",
       "      <td>中山大学南方学院1号实验楼</td>\n",
       "      <td>113.678215,23.631370</td>\n",
       "      <td>172.86</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>B00141TR76</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路29</td>\n",
       "      <td>0.052819</td>\n",
       "      <td>中山大学南方学院教学楼4号</td>\n",
       "      <td>113.677460,23.630490</td>\n",
       "      <td>297.315</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>B0FFKP7Q5N</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路</td>\n",
       "      <td>0.191742</td>\n",
       "      <td>中山大学南方学院2号实验楼</td>\n",
       "      <td>113.678211,23.630956</td>\n",
       "      <td>210.76</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>B00140TWHT</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>笃行路2号</td>\n",
       "      <td>0.157653</td>\n",
       "      <td>教工住宅1号</td>\n",
       "      <td>113.678490,23.630432</td>\n",
       "      <td>251.758</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;住宅小区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>B0G3ARGF5Y</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.286321</td>\n",
       "      <td>中山大学南方学院教学楼1号</td>\n",
       "      <td>113.677077,23.631783</td>\n",
       "      <td>241.753</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;学校;高等院校</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>B0FFLBEOND</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>从莞深高速(中山大学南方学院)</td>\n",
       "      <td>0.190963</td>\n",
       "      <td>聚贤楼10号</td>\n",
       "      <td>113.681253,23.631036</td>\n",
       "      <td>263.444</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;宿舍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>B0FFKP81F0</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路19号附近</td>\n",
       "      <td>0.191742</td>\n",
       "      <td>教学楼1号(文学与传媒学院)</td>\n",
       "      <td>113.676866,23.631736</td>\n",
       "      <td>263.674</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>B0FFKP838K</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路25</td>\n",
       "      <td>0.191742</td>\n",
       "      <td>教学楼3号(外国语学院)</td>\n",
       "      <td>113.677247,23.630947</td>\n",
       "      <td>275.62</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>B0FFJLW0O9</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路4附近</td>\n",
       "      <td>0.191645</td>\n",
       "      <td>中山大学南方学院西区饭堂</td>\n",
       "      <td>113.676210,23.632177</td>\n",
       "      <td>316.572</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>B0FFKPXMCN</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>中山路</td>\n",
       "      <td>0.191739</td>\n",
       "      <td>中山大学南方学院音乐系</td>\n",
       "      <td>113.678792,23.635389</td>\n",
       "      <td>316.942</td>\n",
       "      <td>[]</td>\n",
       "      <td>科教文化服务;科教文化场所;科教文化场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>B0FFJBZLYT</td>\n",
       "      <td>西北</td>\n",
       "      <td>[]</td>\n",
       "      <td>中山路与博学路交叉口东南50米</td>\n",
       "      <td>0.297382</td>\n",
       "      <td>铜像广场</td>\n",
       "      <td>113.676921,23.634555</td>\n",
       "      <td>326.444</td>\n",
       "      <td>[]</td>\n",
       "      <td>风景名胜;风景名胜;风景名胜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>B0FFG8CSEK</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>从莞深高速(中山大学南方学院)</td>\n",
       "      <td>0.185371</td>\n",
       "      <td>L5员工宿舍</td>\n",
       "      <td>113.682583,23.631487</td>\n",
       "      <td>356.923</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;宿舍</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>B0FFKPXO2S</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>博学路附近</td>\n",
       "      <td>0.188247</td>\n",
       "      <td>中山大学南方学院医务室</td>\n",
       "      <td>113.679394,23.635924</td>\n",
       "      <td>372.556</td>\n",
       "      <td>[]</td>\n",
       "      <td>医疗保健服务;医疗保健服务场所;医疗保健服务场所</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>B0FFH6K3U9</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>温泉镇温泉大道882号中大南方H7栋1-5层</td>\n",
       "      <td>0.254885</td>\n",
       "      <td>广州中大南方招待所</td>\n",
       "      <td>113.676330,23.631332</td>\n",
       "      <td>331.438</td>\n",
       "      <td>020-61787222</td>\n",
       "      <td>住宿服务;住宿服务相关;住宿服务相关</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>B0FFHHLMF8</td>\n",
       "      <td>东北</td>\n",
       "      <td>[]</td>\n",
       "      <td>中山大学南方学院明辩路2号第三饭堂</td>\n",
       "      <td>0.178935</td>\n",
       "      <td>茗语轩餐厅</td>\n",
       "      <td>113.681901,23.634495</td>\n",
       "      <td>341.332</td>\n",
       "      <td>13929501395;13533390928</td>\n",
       "      <td>餐饮服务;中餐厅;中餐厅</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>B0FFLJV996</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.286264</td>\n",
       "      <td>保利桃花源66BLOCK</td>\n",
       "      <td>113.682954,23.631008</td>\n",
       "      <td>412.208</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;住宅小区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>B0FFKPXY26</td>\n",
       "      <td>北</td>\n",
       "      <td>[]</td>\n",
       "      <td>从莞深高速公路</td>\n",
       "      <td>0.21826</td>\n",
       "      <td>中山大学南方学院聚贤楼5号</td>\n",
       "      <td>113.680265,23.636313</td>\n",
       "      <td>427.447</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;商务住宅相关;商务住宅相关</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>B0FFGXGN3K</td>\n",
       "      <td>东</td>\n",
       "      <td>[]</td>\n",
       "      <td>中山大学南方学院</td>\n",
       "      <td>0.188657</td>\n",
       "      <td>中山大学南方学院宿舍H25</td>\n",
       "      <td>113.683474,23.632020</td>\n",
       "      <td>430.984</td>\n",
       "      <td>[]</td>\n",
       "      <td>商务住宅;住宅区;宿舍</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            id direction businessarea                 address poiweight  \\\n",
       "0   B00140MR9A         西           []                温泉大道882号  0.450402   \n",
       "1   B0FFF2VMJ4        东南           []       温泉大道886号中山大学南方学院内  0.148531   \n",
       "2   B0FFFTC9PH        东北           []         从莞深高速(中山大学南方学院)  0.193172   \n",
       "3   B00141TQKX        西北           []                 温泉大道882  0.148531   \n",
       "4   B00141TQGR        西北           []                    博学路7  0.148531   \n",
       "5   B00141WQCO        东北           []                     博学路   0.14954   \n",
       "6   B0FFG9IORM        西北           []       温泉大道882号中山大学南方学院内  0.287887   \n",
       "7   B0FFKP9EQJ         东           []                   博学路附近  0.191742   \n",
       "8   B0FFJKIA10        东北           []        温泉大道882号中山大学南方学院  0.191691   \n",
       "9   B00141TRVH        西南           []                   博学路21  0.148531   \n",
       "10  B0FFKERBQZ        西北           []                 博学路7号附近  0.289141   \n",
       "11  B0FFKP81F4        东北           []                     中山路  0.191742   \n",
       "12  B0FFKP9ET5        西南           []                   博学路附近  0.191742   \n",
       "13  B00141TR76        西南           []                   博学路29  0.052819   \n",
       "14  B0FFKP7Q5N        西南           []                     博学路  0.191742   \n",
       "15  B00140TWHT         南           []                   笃行路2号  0.157653   \n",
       "16  B0G3ARGF5Y         西           []                      []  0.286321   \n",
       "17  B0FFLBEOND        东南           []         从莞深高速(中山大学南方学院)  0.190963   \n",
       "18  B0FFKP81F0         西           []                博学路19号附近  0.191742   \n",
       "19  B0FFKP838K        西南           []                   博学路25  0.191742   \n",
       "20  B0FFJLW0O9         西           []                  博学路4附近  0.191645   \n",
       "21  B0FFKPXMCN         北           []                     中山路  0.191739   \n",
       "22  B0FFJBZLYT        西北           []         中山路与博学路交叉口东南50米  0.297382   \n",
       "23  B0FFG8CSEK         东           []         从莞深高速(中山大学南方学院)  0.185371   \n",
       "24  B0FFKPXO2S         北           []                   博学路附近  0.188247   \n",
       "25  B0FFH6K3U9        西南           []  温泉镇温泉大道882号中大南方H7栋1-5层  0.254885   \n",
       "26  B0FFHHLMF8        东北           []       中山大学南方学院明辩路2号第三饭堂  0.178935   \n",
       "27  B0FFLJV996        东南           []                      []  0.286264   \n",
       "28  B0FFKPXY26         北           []                 从莞深高速公路   0.21826   \n",
       "29  B0FFGXGN3K         东           []                中山大学南方学院  0.188657   \n",
       "\n",
       "               name              location distance                        tel  \\\n",
       "0          中山大学南方学院  113.679262,23.632583  2.69979               020-61787331   \n",
       "1      中山大学南方学院-综合楼  113.680117,23.631544  142.466                         []   \n",
       "2    中山大学南方学院教学楼10号  113.680125,23.633492  132.988                         []   \n",
       "3     中山大学南方学院教学楼6号  113.678424,23.633710  153.818                         []   \n",
       "4     中山大学南方学院教学楼7号  113.678600,23.633330  109.298                         []   \n",
       "5     中山大学南方学院教学楼8号  113.680399,23.634329  225.543                         []   \n",
       "6      中山大学南方学院-图书馆  113.679177,23.632762  23.6163  020-61787368;020-61787371   \n",
       "7     中山大学南方学院4号实验楼  113.679963,23.632652  69.4077                         []   \n",
       "8   中山大学南方学院-第11教学楼  113.680037,23.633173  101.294                         []   \n",
       "9     中山大学南方学院教学楼2号  113.677060,23.631346  264.846                         []   \n",
       "10      中山大学南方学院惟贤门  113.678437,23.633721  154.082                         []   \n",
       "11       政商研究院教学楼9号  113.679949,23.633919  163.951                         []   \n",
       "12    中山大学南方学院1号实验楼  113.678215,23.631370   172.86                         []   \n",
       "13    中山大学南方学院教学楼4号  113.677460,23.630490  297.315                         []   \n",
       "14    中山大学南方学院2号实验楼  113.678211,23.630956   210.76                         []   \n",
       "15           教工住宅1号  113.678490,23.630432  251.758                         []   \n",
       "16    中山大学南方学院教学楼1号  113.677077,23.631783  241.753                         []   \n",
       "17           聚贤楼10号  113.681253,23.631036  263.444                         []   \n",
       "18   教学楼1号(文学与传媒学院)  113.676866,23.631736  263.674                         []   \n",
       "19     教学楼3号(外国语学院)  113.677247,23.630947   275.62                         []   \n",
       "20     中山大学南方学院西区饭堂  113.676210,23.632177  316.572                         []   \n",
       "21      中山大学南方学院音乐系  113.678792,23.635389  316.942                         []   \n",
       "22             铜像广场  113.676921,23.634555  326.444                         []   \n",
       "23           L5员工宿舍  113.682583,23.631487  356.923                         []   \n",
       "24      中山大学南方学院医务室  113.679394,23.635924  372.556                         []   \n",
       "25        广州中大南方招待所  113.676330,23.631332  331.438               020-61787222   \n",
       "26            茗语轩餐厅  113.681901,23.634495  341.332    13929501395;13533390928   \n",
       "27     保利桃花源66BLOCK  113.682954,23.631008  412.208                         []   \n",
       "28    中山大学南方学院聚贤楼5号  113.680265,23.636313  427.447                         []   \n",
       "29    中山大学南方学院宿舍H25  113.683474,23.632020  430.984                         []   \n",
       "\n",
       "                        type  \n",
       "0             科教文化服务;学校;高等院校  \n",
       "1               科教文化服务;学校;学校  \n",
       "2       科教文化服务;科教文化场所;科教文化场所  \n",
       "3               科教文化服务;学校;学校  \n",
       "4             科教文化服务;学校;高等院校  \n",
       "5       科教文化服务;科教文化场所;科教文化场所  \n",
       "6             科教文化服务;图书馆;图书馆  \n",
       "7       科教文化服务;科教文化场所;科教文化场所  \n",
       "8       科教文化服务;科教文化场所;科教文化场所  \n",
       "9       科教文化服务;科教文化场所;科教文化场所  \n",
       "10            科教文化服务;学校;高等院校  \n",
       "11      科教文化服务;科教文化场所;科教文化场所  \n",
       "12      科教文化服务;科教文化场所;科教文化场所  \n",
       "13      科教文化服务;科教文化场所;科教文化场所  \n",
       "14      科教文化服务;科教文化场所;科教文化场所  \n",
       "15             商务住宅;住宅区;住宅小区  \n",
       "16            科教文化服务;学校;高等院校  \n",
       "17               商务住宅;住宅区;宿舍  \n",
       "18      科教文化服务;科教文化场所;科教文化场所  \n",
       "19      科教文化服务;科教文化场所;科教文化场所  \n",
       "20      科教文化服务;科教文化场所;科教文化场所  \n",
       "21      科教文化服务;科教文化场所;科教文化场所  \n",
       "22            风景名胜;风景名胜;风景名胜  \n",
       "23               商务住宅;住宅区;宿舍  \n",
       "24  医疗保健服务;医疗保健服务场所;医疗保健服务场所  \n",
       "25        住宿服务;住宿服务相关;住宿服务相关  \n",
       "26              餐饮服务;中餐厅;中餐厅  \n",
       "27             商务住宅;住宅区;住宅小区  \n",
       "28        商务住宅;商务住宅相关;商务住宅相关  \n",
       "29               商务住宅;住宅区;宿舍  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(r.json()['regeocode']['pois'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 路径规划\n",
    "\n",
    "> * 1、步行\n",
    "> * 2、公交车\n",
    "> * 3、驾车"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 步行 \n",
    "\n",
    "> * 1、url:https://restapi.amap.com/v3/direction/walking?parameters    \n",
    "> * 2、requests.get()\n",
    "> * 3、参数：\n",
    "\n",
    ">> * A.必选：key，origin（出发点（经度，纬度））,destination（目的地（经度，纬度））\n",
    ">> * B.可选："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据准备： \n",
    "origin = \"广东省广州市中山大学南方学院\"\n",
    "destination = \"广州市从化区龙岗\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "def geocode(key,address,city=None,batch=None)->str:\n",
    "    url = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "    params = {\n",
    "        \"key\":lin_key,\n",
    "        \"address\":origin,\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    results = response.json()['geocodes'][0]['location']\n",
    "    # 返回值\n",
    "    return results\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function geocode in module __main__:\n",
      "\n",
      "geocode(key, address, city=None, batch=None) -> str\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(geocode)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geocode(lin_key,origin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "起始点_中大南方 = geocode(lin_key,origin)\n",
    "起始点_中大南方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "目的地_龙岗 = geocode(lin_key,destination)\n",
    "目的地_龙岗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 步行\n",
    "url = \"https://restapi.amap.com/v3/direction/walking?parameters\"\n",
    "params = {\n",
    "    \"key\":lin_key,\n",
    "    \"origin\":起始点_中大南方,\n",
    "    \"destination\":目的地_龙岗\n",
    "}\n",
    "r = requests.get(url,params)\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'distance': '1',\n",
       "  'duration': '1',\n",
       "  'steps': [{'instruction': '向南步行1米到达目的地',\n",
       "    'orientation': '南',\n",
       "    'road': [],\n",
       "    'distance': '1',\n",
       "    'duration': '1',\n",
       "    'polyline': '113.679284,23.632574;113.679284,23.632574',\n",
       "    'action': [],\n",
       "    'assistant_action': '到达目的地',\n",
       "    'walk_type': '0'}]}]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()['route']['paths']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 学生练习（路径规划（公交车）（暨南大学-->猎德））：\n",
    "\n",
    "1.公交URL：https://restapi.amap.com/v3/direction/transit/integrated?parameters    \n",
    "2.请求方式：request.get   \n",
    "3.必填参数：key,origin,destination,city   \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import requests,json\n",
    "lin_key =  \"1b65ec2cb8c9419c9b3d6b49b3c001d7\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "def bus(lin_key,origin,destination,city):\n",
    "    bus_url = \"https://restapi.amap.com/v3/direction/transit/integrated?parameters\"\n",
    "    params ={\n",
    "        \"key\":lin_key,\n",
    "        \"origin\":origin,\n",
    "        \"destination\":destination,\n",
    "        \"city\":city\n",
    "    }\n",
    "    r = requests.get(bus_url,params=params)\n",
    "    result = r.json()\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "113.350961,23.131577\n",
      "113.350961,23.131577\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '0',\n",
       " 'route': {'origin': '113.350961,23.131577',\n",
       "  'destination': '113.350961,23.131577',\n",
       "  'distance': '0',\n",
       "  'taxi_cost': '0',\n",
       "  'transits': []}}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "origin = \"广东省广州市暨南大学\"\n",
    "location_orgin = geocode(lin_key,origin)\n",
    "print(location_orgin)\n",
    "destination = \"广东省广州市猎德\"\n",
    "location_destination = geocode(lin_key,destination)\n",
    "print(location_destination)\n",
    "city = \"广州\" \n",
    "results_bus =  bus(lin_key,location_orgin,location_destination,city)\n",
    "results_bus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.0.5'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "#pandas 处理时：{},\n",
    "#1、当表格为一行时，可直接去列name\n",
    "#2、当表格为多行时，去某一行（列表）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-61-c026491032ff>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m_669路_walking\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson_normalize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresults_bus\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'route'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'transits'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'segments'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'walking'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'steps'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0m_669路_bus\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson_normalize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresults_bus\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'route'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'transits'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'segments'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'bus'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'buslines'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0m_669路_walking\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0m_669路_bus\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "_669路_walking = pd.json_normalize(results_bus['route']['transits'][0]['segments'][0]['walking']['steps'])\n",
    "_669路_bus = pd.json_normalize(results_bus['route']['transits'][0]['segments'][0]['bus']['buslines'])\n",
    "_669路_walking\n",
    "_669路_bus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '_669路_bus' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-73-2cd0dd172f77>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0m_669路_bus_via_stops\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjson_normalize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_669路_bus\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'via_stops'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0m_669路_bus_via_stops\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name '_669路_bus' is not defined"
     ]
    }
   ],
   "source": [
    "_669路_bus_via_stops = pd.json_normalize(_669路_bus['via_stops'][0])\n",
    "_669路_bus_via_stops"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.5 行政区域查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "def districy(lin_key,keywords=None,subdistrict=1,page=1,offset=20,extensions=\"all\",filter=None,callback=None,output=\"json\"):\n",
    "    url = \"https://restapi.amap.com/v3/config/district?parameters\"\n",
    "    params = {\n",
    "        \"key\":lin_key,\n",
    "        \"keywords\":keywords,\n",
    "        \"output\":\"json\",\n",
    "        \"subdistrict\":subdistrict,\n",
    "        \"page\":page,\n",
    "        \"offset\":offset,\n",
    "        \"extensions\":extensions,\n",
    "        \"filter\":filter,\n",
    "        \"callback\":callback\n",
    "}\n",
    "    r=requests.get(url,params=params)\n",
    "    district=r.json()\n",
    "    return district"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'district' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-72-255121a3111f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mxingzhengqu\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdistrict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlin_key\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mxingzhengqu\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'district' is not defined"
     ]
    }
   ],
   "source": [
    "xingzhengqu=district(lin_key)\n",
    "xingzhengqu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
